/*
 * @Author: sy
 * @Date: 2021-04-25 08:34:10
 * @LastEditTime: 2023-02-17 09:42:33
 * @Description: file content
 */
import Cookies from "js-cookie";

const cookies = {};

/**
 * @description 存储 cookie 值
 * @param {String} name cookie name
 * @param {String} value cookie value
 * @param {Object} setting cookie setting
 */
cookies.set = function(name = "default", value = "", cookieSetting = {}) {
  const currentCookieSetting = {
    expires: 1
  };
  Object.assign(currentCookieSetting, cookieSetting);
  Cookies.set(`ddmg-financial-pc-${name}`, value, currentCookieSetting);
};

/**
 * @description 拿到 cookie 值
 * @param {String} name cookie name
 */
cookies.get = function(name = "default") {
  return Cookies.get(`ddmg-financial-pc-${name}`);
};

/**
 * @description 拿到 cookie 全部的值
 */
cookies.getAll = function() {
  return Cookies.get();
};

cookies.setByPureKey = function(
  name = "default",
  value = "",
  cookieSetting = {}
) {
  const currentCookieSetting = {
    expires: 1
  };
  Object.assign(currentCookieSetting, cookieSetting);
  Cookies.set(`${name}`, value, currentCookieSetting);
};

cookies.getByPureKey = function(name = "") {
  return Cookies.get(name);
};

cookies.removeByPureKey = function(name = "", cookieSetting = null) {
  if (!cookieSetting) {
    return Cookies.remove(name);
  } else {
    if (name) {
      return Cookies.remove(name, cookieSetting);
    } else {
      return "";
    }
  }
};
/**
 * @description 删除 cookie
 * @param {String} name cookie name
 */
cookies.remove = function(name = "default") {
  return Cookies.remove(`ddmg-financial-pc-${name}`);
};

export default cookies;
